<?php
class App_Model_Role extends Zend_Db_Table_Abstract{
	
	protected $_name = 'rola';
	protected $_primary = 'id';
	
	public function isAdmin($rola){
		
		$rola = ($rola!=null) ? $rola : Zend_Auth::getInstance()->getStorage()->read()->rola;
		
		$select = $this->select()
                    ->from('rola',array('id','nazwa','kod_roli'))
                    ->where("kod_roli =?" ,'ADMIN')
                    ->where("id =?",$rola);
		
		$res = $this->getAdapter()->fetchAll($select);
		if(count($res)==1)
                   return true;
                else
                   return false;	
	}
	public function getRola($konto)
	{
            $select = $this->getAdapter()->select()
                ->from(array('r' => 'rola'), array('id', 'nazwa', 'kod_roli'))
                ->join(array('u' => 'uzytkownik'),'r.id = u.id_rola')
                ->where('u.id =?',$konto);
	  
            return $this->getAdapter()->fetchRow($select);
	}


}
